<?php
include __DIR__ . "/config/cors.php";
include __DIR__ . "/database.php";

$search = @$_GET['search'];
if (!isset($search)) {
    $search = "";
}

$db = new DB();
$sql = "select news.id, news.title, news.context, news.time, news.newImg, user.username
        from news, user where news.uid = user.id and title like '%$search%'
        order by news.time desc";
$data = $db->selectAll($sql);
if (is_array($data) and count($data) > 0) {
    echo json_encode([
        "code" => 200,
        "message" => "查询成功",
        "data" => $data
    ]);
} else {
    echo json_encode([
        "code" => 202,
        "message" => "查询结果为空"
    ]);
}
